/**
 * @swagger
 * tags:
 *   name: Order
 *   description: 订单管理
 */
const express = require('express');
const router = express.Router();
const orderController = require('../controllers/orderController');
const auth = require('../middlewares/auth');
const admin = require('../middlewares/admin');

/**
 * @swagger
 * /api/order:
 *   post:
 *     summary: 创建订单（下单）
 *     tags: [Order]
 *     security:
 *       - bearerAuth: []
 *     requestBody:
 *       required: true
 *       content:
 *         application/json:
 *           schema:
 *             type: object
 *             properties:
 *               items:
 *                 type: array
 *                 items:
 *                   type: object
 *                   properties:
 *                     product_id:
 *                       type: integer
 *                     quantity:
 *                       type: integer
 *               address:
 *                 type: string
 *               contact:
 *                 type: string
 *               remark:
 *                 type: string
 *               phone:
 *                 type: string
 *     responses:
 *       200:
 *         description: 下单成功
 */
router.post('/', auth, orderController.create);

/**
 * @swagger
 * /api/order:
 *   get:
 *     summary: 查询当前用户订单列表
 *     tags: [Order]
 *     security:
 *       - bearerAuth: []
 *     responses:
 *       200:
 *         description: 订单列表
 */
router.get('/', auth, orderController.list);

/**
 * @swagger
 * /api/order/{id}:
 *   get:
 *     summary: 查询订单详情
 *     tags: [Order]
 *     security:
 *       - bearerAuth: []
 *     parameters:
 *       - in: path
 *         name: id
 *         required: true
 *         schema:
 *           type: integer
 *     responses:
 *       200:
 *         description: 订单详情
 */
router.get('/:id', auth, orderController.detail);

/**
 * @swagger
 * /api/order/{id}/status:
 *   put:
 *     summary: 修改订单状态（仅管理员）
 *     tags: [Order]
 *     security:
 *       - bearerAuth: []
 *     parameters:
 *       - in: path
 *         name: id
 *         required: true
 *         schema:
 *           type: integer
 *     requestBody:
 *       required: true
 *       content:
 *         application/json:
 *           schema:
 *             type: object
 *             properties:
 *               status:
 *                 type: string
 *                 description: 新的订单状态
 *     responses:
 *       200:
 *         description: 状态修改成功
 */
router.put('/:id/status', auth, admin, orderController.updateStatus);

/**
 * @swagger
 * /api/order/{id}:
 *   delete:
 *     summary: 删除订单（仅管理员）
 *     tags: [Order]
 *     security:
 *       - bearerAuth: []
 *     parameters:
 *       - in: path
 *         name: id
 *         required: true
 *         schema:
 *           type: integer
 *     responses:
 *       200:
 *         description: 删除成功
 */
router.delete('/:id', auth, admin, orderController.remove);

module.exports = router;
